HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/share/netplan/netplan_cli/cli/commands/__pycache__/apply.cpython-312.pyc
�

z��f�R���dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
ddlmZddlmZmZmZd	Zd
ZGd�de
j,�Zy)
znetplan apply command line�N�)�utils�)�
ConfigManager�ConfigurationError)�apply_sriov_config)�OvsDbServerNotRunning�OvsDbServerNotInstalled�apply_ovs_cleanupznetplan-ovs-cleanup.service�c���eZdZ�fd�Zd�Zd
d�Zed��Zegfd��Zede	fd��Z
edd��Zedd	��Z�xZ
S)�NetplanApplyc�T��t�|�ddd��d|_d|_d|_y)N�applyz.Apply current netplan config to running systemT)�
command_id�description�leafF)�super�__init__�
sriov_only�only_ovs_cleanup�state)�self�	__class__s ��4/usr/share/netplan/netplan_cli/cli/commands/apply.pyrzNetplanApply.__init__,s5���
���G�%U�"�	�	$� ��� %�����
�c��|jjddd��|jjddd��|jjdd�	�|j|_|j	�|j�y)
Nz--sriov-only�
store_truez0Only apply SR-IOV related configuration and exit)�action�helpz--only-ovs-cleanupz1Only clean up old OpenVSwitch interfaces and exitz--statez0Directory containing previous YAML configuration)r )�parser�add_argument�
command_apply�func�
parse_args�run_command)rs r�runzNetplanApply.run4s������ � ���&X�	!�	Z���� � �!5�l�&Y�	!�	[���� � ��&X�	!�	Z��&�&��	��������rc�`�t�}|r||_|jrtj	||�y|j
rtj
|dd|�ydtjvr{tjd�}|�td��tj|ddddd	dd
g�}|dk7r6|rtj|�n|dk(rt!d
��td|z��yd}t#t%j$d��}	t%j$d�}
||
vr|
j'|�t#|
�}t%j$d�}t)j*|t-j.��}
t#|�}g}d}dtjvr#|j1ddg�tj2}|j5t)j6��|rKtj||��dk7r1|r$tjtj8�nt;d��t-j.�}t#t%j$d��}|s|	rd}t%j$d�}||vr|j'|�t#|�}|s|rd}t%j$d�}|
j=t)j*||��t#|�}|s|rd}|rt)j>�|rItAjBd�tj
||||�dg}t)jDd||��ntAjBd�d}|rtAjBd�t)jF�rkd |
vrt)jHd �}|D] }||
vr�	t)jJd!d"|g��"t)jNd|��ntAjBd#�t-j.�}|jQ�tjS||�}|jrpt|j�}|jQ�|jTjW�}|jTjW�}tjY|||�t-j.�}|D]�}tAjBd$|�	tjZd%d&d'd(|zgtj\tj\�)�tjZd%d*d(|zgtj\tj\�)���t-j.�}|j_�D�]\}} | jad,�}!|!s�tc|!�tdk\r&tAjfd-ji|!|���S||vr*|!|vr&tAjBd.ji||!����tjZd/d0d1d2|d3gtj\tj\�)�tjZd/d0d1d2|d,| jad,�gtj\tj\�)���tjZgd4��tjZgd5��tj	||�tjjjmd6�rt)jDd7d8g�|�r
t%j$d9�D�"cgc]!}"tjjjo|"���#}#}"t%j$d:�D�"cgc]9}"|"jqd;trz�stjjjo|"���;}$}"	t)jt�t)jvt)jx��t)jDd7trgd��t)jDd7|#|$zd��|�rt)j*||�}%|%D]}t)jz|��tj|d?d�@�t)jNd7|��d |%vrd}|rgdA�}&tdB�D]m}'tj�|&dd�C�}(|(j�dDk(rt�j�dE��@dFt�|(j��vrnt�j�dG��od |%vr|rt)j�|�yyyy#tjL$rY��wxYw#tjL$rtAjBd+|�Y���wxYwcc}"wcc}"w#tjL$r2tAjfd<�t)jDd=d>gd��Y���wxYw)HNF�SNAP�busctlzmissing busctl utility�callz--quietz--systemzio.netplan.Netplanz/io/netplan/Netplan�Applyr�z'failed to communicate with dbus servicez1failed to communicate with dbus service: error %sz//run/systemd/system/netplan-ovs-cleanup.servicez/run/systemd/network/*netplan-*z!/run/systemd/system/netplan-ovs-*z0/run/NetworkManager/system-connections/netplan-*�NETPLAN_PROFILE�valgrindz--leak-check=full)�stderrz(the configuration could not be generatedTzDnetplan generated networkd configuration changed, reloading networkdznetplan-wpa-*.service�stop)�syncz2no netplan generated networkd configuration exists�z9netplan generated NM configuration changed, restarting NM�lo�device�
disconnectz,no netplan generated NM configuration existsz%netplan triggering .link rules for %s�udevadmztest-builtin�net_setup_linkz/sys/class/net/)�stdoutr0�testz#Ignoring device without syspath: %s�namez5Interface name {} is too long. {} will not be renamedz+Interface rename {} -> {} already happened.�ip�link�set�dev�down)r7�controlz--reload)r7�triggerz
--action=movez--subsystem-match=netz--settlez*/run/systemd/system/netplan-regdom.service�startznetplan-regdom.servicez1/run/systemd/system/*.wants/netplan-wpa-*.servicez1/run/systemd/system/*.wants/netplan-ovs-*.service�/z:Falling back to a hard restart of systemd-networkd.service�restartzsystemd-networkd.servicez/run/NetworkManager/devices)�
ignore_errors)�nmcli�general�status�
)�capture_output�text��z

connectedg�?)Grrrr�process_sriov_configr�process_ovs_cleanup�os�environ�shutil�which�RuntimeError�
subprocessr+�sys�exit�PermissionError�bool�glob�remover�
nm_interfaces�	netifaces�
interfaces�extend�STDOUT�append�get_generator_path�	EX_CONFIGr�update�systemctl_daemon_reload�logging�debug�	systemctl�
nm_running�nm_get_connection_for_interfacerG�CalledProcessError�systemctl_network_manager�parse�process_link_changes�virtual_interfaces�keys�clear_virtual_links�
check_call�DEVNULL�items�get�len�IF_NAMESIZE�warning�format�path�exists�basename�endswith�OVS_CLEANUP_SERVICE�networkctl_reload�networkctl_reconfigure�networkd_interfaces�
ip_addr_flush�rmtree�ranger'�
returncode�time�sleep�strr9�nm_bring_interface_up))r�run_generater2�
exit_on_error�	state_dir�config_managerr*�res�ovs_cleanup_service�old_files_networkd�old_ovs_glob�
old_files_ovs�old_nm_glob�	nm_ifaces�old_files_nm�generator_call�generate_out�devices�restart_networkd�restart_ovs_glob�restart_ovs�restart_nm_glob�
restart_nm�wpa_services�loopback_connectionr5�changes�cm�
prev_links�
curr_links�devices_after_udev�iface�settings�new_name�f�netplan_wpa�netplan_ovsr]�cmd�_�outs)                                         rr#zNetplanApply.command_applyAsk��&����"�D�J��?�?��-�-�n�m�L��
�
"�
"��,�,�^�U�E�=�Y���R�Z�Z���\�\�(�+�F��~�"�#;�<�<��/�/�6�6�9�j�#7�#8�#7�#*�	#%�&�C��a�x� ��H�H�S�M��C�Z�)�A�C�C�'�K�c�Q�S�S��O��!�$�)�)�,M�"N�O���y�y�!D�E���,�.���� 3�4��\�*�
��i�i� R�S���'�'��Y�5I�5I�5K�L�	��K�(��������
�
�*��!�!�:�/B�"C�D�%�,�,�L����e�6�6�8�9��J�O�O�N�<�P�TU�U��������&�(�)S�T�T��&�&�(�� ��	�	�*K� L�M���$6�#���9�9�%H�I���"2�2��#�#�$7�8��+�,���}�#���)�)�$V�W������,�,�_�g�F�G��/�*�
��l��J���)�)�+���M�M�`�a��,�,�^�]�K�Yf�g�3�4�L��O�O�F�L�t�<��M�M�N�O� ����M�M�U�V����!��9�$�*/�*O�*O�PT�*U�'�%��F��Y�.� �����X�|�V�$D�E���/�/��T�B��M�M�H�I��&�&�(��	�����3�3�G�^�L���:�:��t�z�z�*�B��H�H�J��.�.�3�3�5�J�'�:�:�?�?�A�J��,�,�Z��W�M��&�&�(���
	M�F��M�M�A�6�J�
M��%�%�y�.�'7�'8�6�'A�'C�.8�-?�-?�-7�-?�-?�	A�
�%�%�y�&�'8�6�'A�'C�-7�-?�-?�-7�-?�-?�A�
	M�'�1�1�3��&�}�}��	A�O�E�8��|�|�F�+�H���x�=�K�/��O�O�$[�$b�$b�ck�mr�$s�t���G�#��4F�(F��M�M�"O�"V�"V�W\�^f�"g�h���%�%�t�V�U�E�5�&�&Q�-7�-?�-?�-7�-?�-?�A��%�%�t�V�U�',�e�'-�x�|�|�F�/C�'E�.8�-?�-?�-7�-?�-?�	A�	A�*	���@�A����j�k�	�)�)�.�-�H��7�7�>�>�F�G��O�O�G�&>�%?�@��8<�	�	�Bu�8v�w�1�2�7�7�+�+�A�.�w�K�w�8<�	�	�Bu�8v�I�1�"#�*�*�S�3F�-F�"G��7�7�+�+�A�.�I�K�I�
T��'�'�)��,�,�U�-F�-F�-H�I�
�O�O�G�&9�%:��F��O�O�G�[�;�%>�T�J��"�/�/���I�M�&�
+���#�#�E�*�
+�
�M�M�7�t�L��+�+�G�$�?�
�}�$����5���r��	$�A�$�.�.��T��M�C��~�~��*��
�
�1�
� �$��C�J�J��7���J�J�s�O�	$��}�$�)<��+�+�,?�@�*=�$�M��&�8�8�����R�0�0�
M��
�
�C�V�L�
M��Jx��I���0�0�
T���� \�]����	�,F�+G�d�S�S�
T�sD�4d�!A5d.�&e�>e#�;e(�d+�*d+�.)e�e�(Af-�,f-c��|D]N}|j�D]9\}}t|�tur�|jdg�}|D]}||k(s�	y�;�Py)zp
        Is this physical interface a member of a 'composite' virtual
        interface? (bond, bridge)
        r_TF)ru�type�dictrv)�
composites�phy�	compositer�r��membersr�s       r�is_composite_memberz NetplanApply.is_composite_memberDsj��$�	$�I�(���0�
$���8��H�~��-��"�,�,�|�R�8��$�$�E���|�#�$�	
$�	$�rc��|stjd�gStt|�t|�z
�}tt|�j	|��}|D]}	dddd|g}tj|��!|S#t
j$r'tjdj|��Y�]wxYw)a%
        Calculate the delta of virtual links. And remove the links that were
        dropped from the YAML config, if they were not dropped by the backend
        already.
        We can make use of the netplan netdef ids, as those equal the interface
        name for virtual links.
        z;Cannot clear virtual links: no network interfaces provided.r<r=�deleter?zCould not delete interface {})	rgry�listr>�intersectionrVrsrlrz)r�r�r��dropped_interfaces�interfaces_to_clearr=r�s       rrrz NetplanApply.clear_virtual_linksUs�����O�O�Y�Z��I�!�#�j�/�C�
�O�"C�D��#�3�'9�#:�#G�#G��#P�Q��'�	N�D�
N��V�X�u�d�;���%�%�c�*�	N�"�!���0�0�
N���� ?� F� F�t� L�M�
N�s�#B�7B=�<B=r�c��i}|j|jg}|jj�D�]$}|j}|s�|j
s� tj||j�r/tjdj|j���otj||�}|s/tjdj|j����||k(r%tjdj|����|jr2tjdj|j||����d|i||<��'tjdj|��|S)z�
        Go through the pending changes and pick what needs special handling.
        Only applies to non-critical interfaces which can be safely updated.
        zSkipping composite member {}z,Cannot find unique matching interface for {}z&Skipping correctly named interface: {}zLCannot rename {} ({} -> {}) at runtime (needs reboot), due to being criticalr;zLink changes: {})�bridges�bonds�physical_interfaces�values�set_name�
_has_matchrr��idrgrhrzr�find_matching_ifacery�critical)r_r�r��composite_interfaces�netdef�newname�current_iface_names       rroz!NetplanApply.process_link_changesosJ���� .� 6� 6��8L�8L�M��%�8�8�?�?�A�	<�F��o�o�G����$�$���/�/�0D�f�i�i�P��
�
�<�C�C�F�I�I�N�O��!&�!:�!:�:�v�!N��%���� N� U� U�V\�V_�V_� `�a��!�W�,��
�
�F�M�M�g�V�W�������� n�!'���	�	�3E�w�!O�Q��,2�7�*;�G�&�'�7	<�:	�
�
�(�/�/��8�9��rc���	t|�y#tj$rD}tjt|��|rt
jd�Yd}~yYd}~yd}~wwxYw)NrN)rr�
config_errorsrg�errorr�rWrX)r�r��es   rrOz!NetplanApply.process_sriov_config�sJ��	��~�.���"�"�	��M�M�#�a�&�!����������	�s��A%�5A � A%c��	t|||�y#ttf$rD}tjt|��|rt
jd�Yd}~yYd}~yd}~wt$r.}tjdj|��Yd}~yd}~wt$r }tjd|�Yd}~yd}~wwxYw)NrNzCannot call Open vSwitch: {}.zCannot call Open vSwitch: %s.)
r�OSErrorrUrgr�r�rWrXr	ryrzr
rh)r��ovs_old�ovs_currentr�r�s     rrPz NetplanApply.process_ovs_cleanup�s���		>��n�g�{�C����&�	��M�M�#�a�&�!����������$�	G��O�O�;�B�B�1�E�F�F��&�	>��M�M�9�1�=�=��	>�s,�
�B?�5A�B?�*$B�B?�B:�:B?)TFTN)T)�__name__�
__module__�__qualname__rr'r#�staticmethodr�rrrrorOrP�
__classcell__)rs@rrr*s������AA�F���� �<>�"��"�2�)��)��)�V�����
>��
>rr)�__doc__rgrQrWr[rVrSr^r�r3r�
configmanagerrr�sriovr�ovsr	r
rrrx�NetplanCommandr�rr�<module>r�sR��(!��	�
���
����>�&�S�S�4����E>�5�'�'�E>r